package portal.mybatis.dao.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.CommitJob;
import portal.mybatis.dao.HistoryJob;
import portal.mybatis.dao.mapper.HistoryJobMapper;

@Service
public class HistoryJobService {
	@Autowired
	private HistoryJobMapper hjMapper;
	public boolean insertJobState(CommitJob commitJob, String taskHash, String algorithmBlockId, String jobId, String algorithmId, String index, String jobName,String fullInfo){
		HistoryJob job= new HistoryJob(commitJob,taskHash,algorithmBlockId,jobId,algorithmId,index,jobName,fullInfo);
		int ret=hjMapper.insertSelective(job);
		return ret>0;
	}
	public boolean updateJobState(String status,String jobName,String fullInfo, String subTaskHash,String algorithmHash,String jobId) {
		return updateJobState(status, jobName, fullInfo, subTaskHash, algorithmHash, jobId, new Date());
	}
	public boolean updateRunningJobState(String status,String jobName,String fullInfo, String subTaskHash,String algorithmHash,String jobId) {
		return updateJobState(status, jobName, fullInfo, subTaskHash, algorithmHash, jobId, null);
	}
	private boolean updateJobState(String status,String jobName,String fullInfo, String subTaskHash,String algorithmHash,String jobId,Date date){
		HistoryJob job =new HistoryJob(status,jobName,fullInfo,subTaskHash,algorithmHash,jobId,date);
		int ret =hjMapper.updateByPrimaryKeySelective(job);
		return ret>0;
	}
}
